package com.awcall.iot.utils;

import org.apache.commons.codec.digest.DigestUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by wuhui on 2017/4/14
 */
public class SendSMS {

    private static final String NAME = "daniufeimao";
    private static final String PWD = "daniufeimao3251";
    private static final String USER_ID = "34";

    public static Map<String,String> send(String telephone, String message,String method) {
        Long timestamp = System.currentTimeMillis();
        String sign = DigestUtils.md5Hex(NAME+PWD+timestamp);
        Map<String, String> paramMap = new HashMap<>();
        System.out.println(NAME);
        System.out.println(PWD);
        System.out.println(timestamp);
        System.out.println(sign);
        paramMap.put("action",method);
        paramMap.put("userid",USER_ID);
        paramMap.put("timestamp",timestamp.toString());
        paramMap.put("sign",sign);
        paramMap.put("mobile",telephone);
        paramMap.put("content",message);
        Map<String,String> result= new OkHttpUtils("http://211.154.194.50:8888/v2sms.aspx/")
                .post()
                .formParams(paramMap)
                .execute()
                .asXmlMap();
        return result;
    }

    public static void main(String[] args) {
        String msgPre = "【财务系统】尊敬的用户，(修改密码操作)手机验证码为：";
        String msgEnd = "。该验证码10分钟内有效，如非本人操作请忽略。";
        String msg = msgPre+"951221"+msgEnd;
        send("13521948465", msg,"send");
    }

}
